//
//  NYRecommendCollectionViewCell.m
//  Nooryes
//
//  Created by baken on 2020/2/20.
//  Copyright © 2020 MyApp. All rights reserved.
//

#import "NYRecommendCollectionViewCell.h"
#import "NYArticleListModel.h"

@interface NYRecommendCollectionViewCell()
@property (nonatomic, strong) UIImageView *avatar;
@property (nonatomic, strong) UIImageView *type;
@property (nonatomic, strong) UILabel *num;
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *name;


@property (nonatomic, strong) NSIndexPath *index;
@end

@implementation NYRecommendCollectionViewCell


+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView
                              indePath:(NSIndexPath *)indexPath{
     NYRecommendCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kNYRecommendCollectionViewCell forIndexPath:indexPath];
    cell.layer.masksToBounds = YES;
    cell.layer.cornerRadius = 8;
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}

-(void)setModel:(ArticleListModel *)model{
    _model = model;
    self.title.text = model.title;
    self.name.text = model.nickname;
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:model.userimg]];
    self.num.text = model.zan;
    if ([model.type isEqualToString:@"1"]) {
         self.type.image = [UIImage imageNamed:@"zhongcao"];
    } else if ([model.type isEqualToString:@"2"]) {
         self.type.image = [UIImage imageNamed:@"bacao"];
    } else {
         self.type.image = [UIImage imageNamed:@"bacao"];
    }
   
    
    
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.bottom.offset(-85);
    }];
    [self.avatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.top.mas_equalTo(self.imageView.mas_bottom).offset(10);
        make.left.offset(10);
    }];
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.avatar.mas_right).offset(5);
        make.centerY.mas_equalTo(self.avatar.mas_centerY);
    }];
    [self.type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(15, 15));
        make.centerY.mas_equalTo(self.avatar.mas_centerY);
        make.right.offset(-40);
    }];
    [self.num mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.type.mas_right).offset(5);
        make.centerY.mas_equalTo(self.avatar.mas_centerY);
    }];
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.right.offset(-10);
        make.top.mas_equalTo(self.avatar.mas_bottom).offset(12);
        
    }];
}

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        _imageView.backgroundColor = [UIColor grayColor];
        
    }
    return _imageView;
}

-(UIImageView *)avatar{
    if (!_avatar) {
        _avatar = [[UIImageView alloc] init];
        _avatar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        _avatar.contentMode = UIViewContentModeScaleAspectFill;
        _avatar.layer.masksToBounds = YES;
        _avatar.layer.cornerRadius = 10;
        
    }
    return _avatar;
}

-(UIImageView *)type{
    if (!_type) {
        _type = [[UIImageView alloc] init];
        _type.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        _type.contentMode = UIViewContentModeScaleAspectFit;
        
    }
    return _type;
}

-(UILabel *)num{
    if (!_num) {
        _num = [[UILabel alloc] init];
        _num.textAlignment = NSTextAlignmentLeft;
        _num.textColor = UIColorFromRGB(0x999999);
        _num.font = [UIFont systemFontOfSize:12];
    }
    return _num;
}

-(UILabel *)name{
    if (!_name) {
        _name = [[UILabel alloc] init];
        _name.textAlignment = NSTextAlignmentLeft;
        _name.textColor = UIColorFromRGB(0x999999);
        _name.font = [UIFont systemFontOfSize:12];
    }
    return _name;
}

-(UILabel *)title{
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textAlignment = NSTextAlignmentLeft;
        _title.textColor = UIColorFromRGB(0x333333);
        _title.font = [UIFont boldSystemFontOfSize:14];
        _title.numberOfLines = 2;
    }
    return _title;
}

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self.contentView addSubview:self.imageView];
        [self.contentView addSubview:self.avatar];
        [self.contentView addSubview:self.type];
        [self.contentView addSubview:self.num];
        [self.contentView addSubview:self.title];
        [self.contentView addSubview:self.name];
         
    }
    return self;
}

@end
